/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converters;

import DAO.PeriodicoGSDao;
import bean.PeriodicoGS;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author fernando
 */
@FacesConverter(forClass=PeriodicoGS.class)
public class PeriodicoGSConverter implements Converter {
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if(value==null || value.isEmpty() ){
            return null;
        }
        return new PeriodicoGSDao().buscar((Integer.valueOf(value))) ;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        PeriodicoGS periodico = (PeriodicoGS) value;
        System.out.println("O id do trabalhoGs no converter:" + periodico.getId());
        if(periodico == null || periodico.getId() <= 0){
            return null;
        }
        return String.valueOf(periodico.getId());
    }
    
}
